2.2 Training With Multiple Inputs
With multiple inputs, each input has its own weight.
Error:
Loss:
3.3 Gradients
Each weight gets its own gradient.
Bias:
3.4 Updating Weights
Each parameter is updated independently.
3.5 Training Loop
x1 = 2
x2 = 3
target = 13
w1 = 1
w2 = 1
b = 0
learning_rate = 0.01
for step in range(100):
prediction = w1 * x1 + w2 * x2 + b
error = target - prediction
loss = error ** 2
gradient_w1 = -2 * x1 * error
gradient_w2 = -2 * x2 * error
gradient_b = -2 * error
w1 = w1 - learning_rate * gradient_w1
w2 = w2 - learning_rate * gradient_w2
b = b - learning_rate * gradient_b
print( "step:", step, "| prediction:", prediction, "| loss:", round(loss,3), "| w1:", round(w1, 3), "| w2:", round(w2, 3), "| b:", round(b, 3) )
print('final formula becomes: ',round(w1, 2)," x1 + ",round(w2, 2),"x2 + ",round(b,2))